import java.util.Scanner;

public class WoodenSticks {	
	public static void main(String[] args)  {
		Scanner inscanner = new Scanner(System.in);		
		int tt = inscanner.nextInt();//read total test cases
		
		for(int i=0;i<tt;i++) {			
			int n = inscanner.nextInt(); //read the number of wooden sticks
			WoodenStick[] woodenSticks = new WoodenStick[n];
			for(int j=0;j<n;j++) {
				int length = inscanner.nextInt();
				int weight = inscanner.nextInt();
				WoodenStick woodenStick = new WoodenStick(length, weight);
				woodenSticks[j] =woodenStick;
			}
			
			int minSetupTime = CalculateMinSetupTime(woodenSticks);
			System.out.println(minSetupTime);
		}
	}
	
	private static int CalculateMinSetupTime(
			WoodenStick[] woodenSticks) {
		int setupTimes = 0;
		
//		BubbleSort(woodenSticks);
		QuickSort(woodenSticks, 0, woodenSticks.length -1);
		
		int[] indicators = new int[woodenSticks.length];
		for(int i=0; i < woodenSticks.length; i++ ) {
			if (indicators[i] == 0) {
				setupTimes++;
				indicators[i] = 1;
				WoodenStick temp = woodenSticks[i];
				for(int j=i+1; j< woodenSticks.length;j++) {
					if(indicators[j]==0 && woodenSticks[j].weight >= temp.weight) {
						indicators[j] = 1;
						temp = woodenSticks[j];
					}
				}
			}
		}
		
		return setupTimes;
	}
	
	/*
	 * sorting the wooden sticks by the length first and then by the weight if the length is equal
	 */
	private static void BubbleSort(WoodenStick[] woodenSticks) {		
		for(int i=0;i<woodenSticks.length; i++) {
			for(int j=i+1;j<woodenSticks.length;j++) {
				if (Compare(woodenSticks[i],woodenSticks[j])) {
					WoodenStick temp = woodenSticks[i];
					woodenSticks[i] = woodenSticks[j];
					woodenSticks[j] = temp;
				}
			}
		}
	}
	
	public static void QuickSort(WoodenStick[] theArray, int left, int right) {
		if (right - left <= 0) // if size <= 1,
			return; // already sorted
		else // size is 2 or larger
		{
			WoodenStick pivot = theArray[right]; // rightmost item
			// partition range
			int partition = PartitionIt(theArray, left, right, pivot);
			QuickSort(theArray, left, partition - 1); // sort left side
			QuickSort(theArray, partition + 1, right); // sort right side
		}
	} // end recQuickSort()

	public static int PartitionIt(WoodenStick[] theArray, int left, int right,
			WoodenStick pivot) {
		int leftPtr = left - 1; // left (after ++)
		int rightPtr = right; // right-1 (after --)
		while (true) {
			// find bigger item
			while (Compare(pivot, theArray[++leftPtr]))
				; 
			// find smaller item
			while (rightPtr > 0 && Compare(theArray[--rightPtr], pivot))
				; 

			if (leftPtr >= rightPtr) // if pointers cross,
				break; // partition done
			else
				// not crossed, so
				swap(theArray, leftPtr, rightPtr); 
		} 
		swap(theArray, leftPtr, right); // restore pivot
		
		return leftPtr; // return pivot location
	} 

	public static void swap(WoodenStick[] theArray, int dex1, int dex2) // swap two
																	// elements
	{
		WoodenStick temp = theArray[dex1]; 
		theArray[dex1] = theArray[dex2]; 
		theArray[dex2] = temp; 
	} 
	
	private static boolean Compare(WoodenStick ws1, WoodenStick ws2) {
		if (ws1.length > ws2.length ){
			return true;
		} else if (ws1.length == ws2.length ) {
			return ws1.weight > ws2.weight ;
		}
		
		return false;		
	}
	
	private static class WoodenStick {
		public int length;
		public int weight;
		
		WoodenStick(int l, int w) {
			this.length = l;
			this.weight = w;
		}
	}
}
